package com.example.controll.user_lease;

import com.example.config.R;
import com.example.domain.user_lease;
import com.example.service.lease.leaseService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/lease")
public class leaseControll {

    @Resource
    private leaseService leaseService;

    @RequestMapping("/insert")
    private R insert(user_lease userLease){
//        long time = new Date().getTime();
//        System.currentTimeMillis();
        System.out.println(System.currentTimeMillis());
        String s = String.valueOf(System.currentTimeMillis());
        userLease.setOrder_number(s);

        boolean flag=leaseService.insert(userLease);
        return new R (flag,flag?"添加成功":"添加失败");
//        return new R (false,false?"添加成功":"添加成功");
    }

    @RequestMapping("/update")
    private R updateNumber(user_lease userLease){
        String openid=userLease.getUser_openid();
        int articlesid = userLease.getArticlesid();
        openid="'"+openid+"'";

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(simpleDateFormat.format(date));
        String format = simpleDateFormat.format(date);

        int yuqifeiyong = userLease.getYuqifeiyong();


        boolean flag = leaseService.updata(openid, articlesid,format,yuqifeiyong);
        return new R (flag,flag?"更新成功":"更新失败");
    }

}
